package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.LogLoginService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.LogLoginDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/logLogin")
public class LogLoginController extends BaseController {

    @Resource
    private LogLoginService logLoginService;

    @Resource
    private UserService userService;

    @GetMapping("/list")
    public ServerResponse list(HttpServletRequest request, LogLoginDto logLoginDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logLoginService.findListByKeyword(userInfo, logLoginDto);
    }

    /**
     * 删除登录日志
     *
     * @return
     */
    @DeleteMapping("/{id}")
    public ServerResponse delete(HttpServletRequest request, @PathVariable Integer id) {
        UserInfo userInfo = userService.getLoginUserInfo(request);

        return logLoginService.delete(id);
    }

    /**
     * 删除登录日志
     *
     * @return
     */
    @PostMapping("/batchDeleteInIds")
    public ServerResponse deleteInIds(HttpServletRequest request, @RequestBody LogLoginDto logLoginDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logLoginService.batchDelete(logLoginDto);
    }


    /**
     * 删除登录日志
     *
     * @return
     */
    @PostMapping("/deleteInStartAndEndDateTime")
    public ServerResponse deleteInStartAndEndDateTime(HttpServletRequest request, @RequestBody LogLoginDto logLoginDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        return logLoginService.deleteInStartAndEndDateTime(logLoginDto);
    }
}

